<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改状态流程实例')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-statusProcess-edit" th:object="${statusProcess}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">运行类型：</label>
                <div class="col-sm-8">
                    <select name="runType" class="form-control m-b" th:with="type=${@dict.getType('runType')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{runType}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">状态类型：</label>
                <div class="col-sm-8">
                    <select name="statusType" class="form-control m-b" th:with="type=${@dict.getType('statusType')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{statusType}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">场景模型：</label>
                <div class="col-sm-8">
                    <select name="sceneModel" id="sceneModel" class="form-control m-b" th:with="type=${@dict.getType('sceneModel')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{sceneModel}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">关联状态id：</label>
                <div class="col-sm-8">
                    <select name="relationStatusId" id="relationStatusId" class="form-control m-b" required>
                        <option value="">请选择</option>
                        <option th:each="status : ${statusList}" th:text="${status.statusZhName}" th:value="${status.id}" th:field="*{relationStatusId}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">关联前面状态id：</label>
                <div class="col-sm-8">
                    <select name="relationPreStatusId" id="relationPreStatusId" class="form-control m-b">
                        <option value="">请选择</option>
                        <option th:each="status : ${statusList}" th:text="${status.statusZhName}" th:value="${status.id}" th:field="*{relationPreStatusId}"></option>
                    </select>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "statusProcess/statusProcess";
        $("#form-statusProcess-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-statusProcess-edit').serialize());
            }
        }

        $(function () {
            $("#sceneModel").change(function() {
                loadData($(this).val());
            });
        });

        function loadData(sceneModel) {
            if (!sceneModel) return;

            var config = {
                url: prefix + '/selectStatus?sceneModel='+sceneModel,
                type: "post",
                dataType: "json",
                data: null,
                success: function(result) {
                    if (result.code == web_status.SUCCESS) {
                        $("#relationStatusId").empty();
                        $("#relationPreStatusId").empty();
                        if(result.data && result.data.length > 0) {
                            $("#relationStatusId").append('<option value="">请选择</option>');
                            $("#relationPreStatusId").append('<option value="">请选择</option>');
                            for (var i=0; i< result.data.length; i++) {
                                $("#relationStatusId").append('<option value="'+result.data[i].id+'">'+result.data[i].statusZhName+'</option>')
                                $("#relationPreStatusId").append('<option value="'+result.data[i].id+'">'+result.data[i].statusZhName+'</option>')
                            }
                        }
                    }
                }
            };
            $.ajax(config);
        }
    </script>
</body>
</html>